package com.shangyueshang.model;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.shangyueshang.enums.Channel;
import com.shangyueshang.enums.ShipStatus;
import com.shangyueshang.enums.PayStatus;
import com.shangyueshang.handlers.ChannelHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.util.Objects;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2022/2/18 17:18
 * @version: v1.0.0
 *
 * <p>发货记录表</p>
 */
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class ShippingRecord extends BaseModel {

    /**
     * SKU
     */
    private String sku;

    /**
     * 产品名称
     */
    private String productName;

    /**
     * 所属店铺
     */
    private String shop;

    /**
     * 渠道
     */
    @TableField(typeHandler = ChannelHandler.class)
    private Channel channel;

    /**
     * 货运代理ID
     */
    private Long freightForwarderId;

    /**
     * 运输状态，默认：待取货(wait_pick)
     */
    @EnumValue
    private ShipStatus shipStatus;

    /**
     * 发货日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate shipDate;

    /**
     * 签收日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate receiptDate;

    /**
     * FBA货件号
     */
    private String fbaShipmentNo;

    /**
     * 货代运单号
     */
    private String waybillNo;

    /**
     * 产品数量
     */
    private Integer productQuantity;

    /**
     * 货件数（箱）
     */
    private Integer shipQuantity;

    /**
     * 自称重量，单位：kg
     */
    private BigDecimal selfWeight;

    /**
     * 计费重量，单位：kg
     */
    private BigDecimal chargeWeight;

    /**
     * 运输费用，单位：元
     */
    private BigDecimal shipFee;

    /**
     * 运输单价，单位：元
     */
    private BigDecimal shipUnitPrice;

    /**
     * 付款状态，1-已付款 0-未付
     */
    @EnumValue
    private PayStatus payStatus;

    /**
     * 计算运输天数
     *
     * @return
     */
    public long getTransportDays() {
        if (Objects.isNull(shipDate) || Objects.isNull(receiptDate)) {
            return -1;
        }
        return Duration.between(shipDate, receiptDate).toDays();
    }
}
